package com.tank.game.core;

import cn.hutool.core.util.RandomUtil;
import com.tank.game.api.LaunchPanelUtils;
import com.tank.game.api.Position;

import java.awt.*;

/**
 * 缺省度数
 *
 * @author Zed
 */
public class DefaultPosition implements Position {

    private int degree;

    private int x;

    private int y;

    @Override
    public int getDegree() {
        return this.degree;
    }

    @Override
    public int getX() {
        return this.x;
    }

    @Override
    public int getY() {
        return this.y;
    }

    @Override
    public void setX(int x) {
        this.x = x;
    }

    @Override
    public void setY(int y) {
        this.y = y;
    }

    @Override
    public void setDegree(int degree) {
        this.degree = degree;
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    /**
     * 创建Builder构建器
     *
     * @return {@link Builder}
     */
    public static Builder newGamePanelRandomPositionBuilder() {
        Builder builder = new Builder();
        Dimension dimension = LaunchPanelUtils.LAUNCH_PANEL.getDimension();
        builder.degree(RandomUtil.randomInt(0, 360));
        builder.x(RandomUtil.randomInt(0, (int) dimension.getWidth()));
        builder.y(RandomUtil.randomInt(0, (int) dimension.getHeight()));
        return builder;
    }


    public static final class Builder {
        private int degree;
        private int x;
        private int y;


        public Builder degree(int degree) {
            this.degree = degree;
            return this;
        }

        public Builder x(int x) {
            this.x = x;
            return this;
        }

        public Builder y(int y) {
            this.y = y;
            return this;
        }

        public DefaultPosition build() {
            DefaultPosition defaultPosition = new DefaultPosition();
            defaultPosition.setDegree(degree);
            defaultPosition.setX(x);
            defaultPosition.setY(y);
            return defaultPosition;
        }
    }
}
